home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume16 / ecu3-excel / part02 < prev    next >
Encoding:
Internet Message Format  |  1991-01-13  |  41.7 KB

  1. From: wht@n4hgf.Mt-Park.GA.US
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i073:  ECU 3 log-to-Excel spreadsheet, Part02/02
  4. Message-ID: <1991Jan12.210241.14311@sparky.IMD.Sterling.COM>
  5. Date: 12 Jan 91 21:02:41 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: b2b31cc2 853564b9 20ff7214 5e7b12a6
  8.  
  9. Submitted-by: wht@n4hgf.Mt-Park.GA.US
  10. Posting-number: Volume 16, Issue 73
  11. Archive-name: ecu3-excel/part02
  12.  
  13. #!/bin/sh
  14. # This is part 02 of ecu3-excel
  15. # ============= excel/ecuxls.c ==============
  16. if test ! -d 'excel'; then
  17.     echo 'x - creating directory excel'
  18.     mkdir 'excel'
  19. fi
  20. if test -f 'excel/ecuxls.c' -a X"$1" != X"-c"; then
  21.     echo 'x - skipping excel/ecuxls.c (File already exists)'
  22. else
  23. echo 'x - extracting excel/ecuxls.c (Text)'
  24. sed 's/^X//' << 'SHAR_EOF' > 'excel/ecuxls.c' &&
  25. X/* CHK=0x149E */
  26. Xchar *revision = "1.00";
  27. X/*+-------------------------------------------------------------------------
  28. X    ecuxls.c - place ECU log info in Excel spreadsheets
  29. X    wht@n4hgf.Mt-Park.GA.US
  30. X
  31. X  Defined functions:
  32. X    ce_list_add(tce)
  33. X    ce_list_remove(tce)
  34. X    ce_list_search(pid)
  35. X    get_home_dir(home_dir)
  36. X    log_connect(logbuf)
  37. X    log_disconnect(x,logbuf)
  38. X    log_receive(x,logbuf)
  39. X    main(argc,argv)
  40. X    make_brFONT(name,height,attr)
  41. X    make_brFORMAT(picture)
  42. X    make_brLABEL(str)
  43. X    make_brNAME_area(name,firstrow,firstcol,rows,cols)
  44. X    make_brNAME_cell(name,row,col)
  45. X    rearranged_date(date)
  46. X    strlwr(str)
  47. X    xls_append(filename)
  48. X    xls_create_Clog(filename)
  49. X    xls_create_Rlog(filename)
  50. X    xls_get_brDIMENSION(x,dimension)
  51. X    xls_now(now)
  52. X    xls_write_Clog_record(x,row,date,sys,phone,secs)
  53. X    xls_write_Rlog_record(x,row,date,from,length,name)
  54. X    xls_write_br(x,bhdr)
  55. X    xls_write_eof_and_close(x)
  56. X
  57. X--------------------------------------------------------------------------*/
  58. X/*+:EDITS:*/
  59. X/*:01-01-1990-16:19-wht@n4hgf-creation */
  60. X
  61. X#include <stdio.h>
  62. X#ifdef NULL
  63. X#undef NULL
  64. X#endif
  65. X#include <sys/types.h>
  66. X#include <sys/stat.h>
  67. X#include <ctype.h>
  68. X#include <errno.h>
  69. X#include <fcntl.h>
  70. X#include <malloc.h>
  71. X#include <memory.h>
  72. X#include <signal.h>
  73. X#include <string.h>
  74. X#include <time.h>
  75. X#include <pwd.h>
  76. X
  77. X#include "biff.h"
  78. X
  79. Xlong atol();
  80. X
  81. Xtypedef struct xls_file
  82. X{
  83. X    char filename[128];
  84. X    FILE *fp;
  85. X    long dimension_fpos;
  86. X    int first_data_row;
  87. X    int last_data_row;
  88. X} XLS_FILE;
  89. X
  90. Xtypedef struct ce        /* connection linked list entry */
  91. X{
  92. X    struct ce *prev;
  93. X    struct ce *next;    /* we don't need double links, but logic was handy */
  94. X    int pid;            /* ecu pid for a connection */
  95. X    char sys[32];        /* system connected to */
  96. X    char date[32];
  97. X} CE;
  98. X
  99. X#if defined(__STDC__)
  100. Xvoid ce_list_add(struct ce *);
  101. Xvoid ce_list_remove(struct ce *);
  102. Xstruct ce *ce_list_search(int);
  103. Xint get_home_dir(char *);
  104. Xvoid strlwr(char *);
  105. Xdouble xls_now(long);
  106. Xstruct brLABEL *make_brLABEL(char *);
  107. Xstruct brFONT *make_brFONT(char *,int,int);
  108. Xstruct brFORMAT *make_brFORMAT(char *);
  109. Xstruct brNAME *make_brNAME_cell(char *,int,int);
  110. Xstruct brNAME *make_brNAME_area(char *,int,int,int,int);
  111. Xlong xls_write_br(struct xls_file *,struct bhdr *);
  112. Xlong xls_get_brDIMENSION(struct xls_file *,struct brDIMENSION *);
  113. Xstruct xls_file *xls_append(char *);
  114. Xstruct xls_file *xls_create_Rlog(char *);
  115. Xlong xls_write_Rlog_record(struct xls_file *,int,char *,char *,long,char *);
  116. Xstruct xls_file *xls_create_Clog(char *);
  117. Xlong xls_write_Clog_record(struct xls_file *,int,char *,char *,char *,long);
  118. Xvoid xls_write_eof_and_close(struct xls_file *);
  119. Xchar *rearranged_date(char *);
  120. Xvoid log_connect(char *);
  121. Xint log_disconnect(struct xls_file *,char *);
  122. Xvoid log_receive(struct xls_file *,char *);
  123. Xint main(int,char **);
  124. X#else
  125. Xvoid ce_list_add();
  126. Xvoid ce_list_remove();
  127. Xstruct ce *ce_list_search();
  128. Xint get_home_dir();
  129. Xvoid strlwr();
  130. Xdouble xls_now();
  131. Xstruct brLABEL *make_brLABEL();
  132. Xstruct brFONT *make_brFONT();
  133. Xstruct brFORMAT *make_brFORMAT();
  134. Xstruct brNAME *make_brNAME_cell();
  135. Xstruct brNAME *make_brNAME_area();
  136. Xlong xls_write_br();
  137. Xlong xls_get_brDIMENSION();
  138. Xstruct xls_file *xls_append();
  139. Xstruct xls_file *xls_create_Rlog();
  140. Xlong xls_write_Rlog_record();
  141. Xstruct xls_file *xls_create_Clog();
  142. Xlong xls_write_Clog_record();
  143. Xvoid xls_write_eof_and_close();
  144. Xchar *rearranged_date();
  145. Xvoid log_connect();
  146. Xint log_disconnect();
  147. Xvoid log_receive();
  148. X#endif
  149. X
  150. X#define HEADER_ROW            0
  151. X#define HEADER_COL            0
  152. X
  153. X#define LABEL_ROW            1
  154. X#define Rlog_DATE_COL        0
  155. X#define Rlog_FROM_COL        1
  156. X#define Rlog_LENGTH_COL        2
  157. X#define Rlog_NAME_COL        3
  158. X
  159. X#define Clog_DATE_COL        0
  160. X#define Clog_SYS_COL        1
  161. X#define Clog_PHONE_COL        2
  162. X#define Clog_TIME_COL        3
  163. X
  164. X#define TOTAL_DATA_ROWS    4000
  165. X
  166. X#define FONT_HELV10            0
  167. X#define FONT_HELV10_BOLD    1
  168. X
  169. X#define FORMAT_GENERAL        0
  170. X#define Rlog_FORMAT_DATE    1
  171. X#define Clog_FORMAT_TIME    1
  172. X#define FORMAT_COUNT        1    /* do not count "General" */
  173. X
  174. XCE *ce_list_head = (CE *)0;
  175. X
  176. X/*+-------------------------------------------------------------------------
  177. X    ce_list_add(tce) -- add to linked list
  178. X--------------------------------------------------------------------------*/
  179. Xvoid
  180. Xce_list_add(tce)
  181. XCE *tce;
  182. X{
  183. Xregister CE *this = tce;
  184. Xregister CE *prev;
  185. Xregister CE *next;
  186. X
  187. X/* if empty, init list with this one and quit */
  188. X    if(ce_list_head == (CE *)0)
  189. X    {
  190. X        ce_list_head = this;
  191. X        this->prev = (CE *)0;
  192. X        this->next = (CE *)0;
  193. X        return;
  194. X    }
  195. X
  196. X/* list not empty */
  197. X    prev = (CE *)0;        /* no previous yet */
  198. X    next = ce_list_head;    /* init next to top of list */
  199. X
  200. X    while(next->pid < this->pid)
  201. X    {
  202. X        prev = next;
  203. X        next = prev->next;
  204. X        if(next == (CE *)0)
  205. X            break;
  206. X    }
  207. X
  208. X    if(prev)        /* if non-zero, we will not update the list head */
  209. X    {
  210. X        this->next = prev->next;
  211. X        this->prev = prev;
  212. X        prev->next = this;
  213. X        if(next)
  214. X            next->prev = this;
  215. X    }
  216. X    else    /* 'this' is to become the new list head (1st element) */
  217. X    {
  218. X        this->next = next;
  219. X        this->prev = (CE *)0;
  220. X        if(next)
  221. X            next->prev = this;
  222. X        ce_list_head = this;
  223. X    }
  224. X
  225. X}    /* end of ce_list_add */
  226. X
  227. X/*+-------------------------------------------------------------------------
  228. X    ce_list_remove(tce) -- remove from linked list
  229. X--------------------------------------------------------------------------*/
  230. Xvoid
  231. Xce_list_remove(tce)
  232. Xregister CE *tce;
  233. X{
  234. Xregister CE *prev;
  235. Xregister CE *next;
  236. X
  237. X    prev = (CE *)0;    /* there is no previous now */
  238. X
  239. X    if((next = ce_list_head) == (CE *)0)    /* if empty list */
  240. X        return;
  241. X
  242. X    while(next != tce)
  243. X    {
  244. X        prev = next;
  245. X        next = prev->next;
  246. X        if(next == (CE *)0)
  247. X            return;
  248. X    }
  249. X
  250. X/* unlink */
  251. X    if(prev)        /* if non-zero, we will not update the list head */
  252. X    {
  253. X        prev->next = tce->next;
  254. X        if(tce->next)
  255. X            (tce->next)->prev = prev;
  256. X    }
  257. X    else
  258. X    {
  259. X        ce_list_head = tce->next;
  260. X        if(tce->next)
  261. X            (tce->next)->prev = (CE *)0;
  262. X    }
  263. X
  264. X    tce->next = (CE *)0;
  265. X    tce->prev = (CE *)0;
  266. X
  267. X}    /* end of ce_list_remove */
  268. X
  269. X/*+-----------------------------------------------------------------------
  270. X    CE *ce_list_search(pid)
  271. X------------------------------------------------------------------------*/
  272. XCE *
  273. Xce_list_search(pid)
  274. Xint pid;
  275. X{
  276. Xregister CE *tce;
  277. X
  278. X    tce = ce_list_head;
  279. X    while(tce)
  280. X    {
  281. X        if(tce->pid == pid)
  282. X            return(tce);
  283. X        tce = tce->next;
  284. X    }
  285. X    return(tce);
  286. X
  287. X}    /* end of ce_list_search */
  288. X
  289. X/*+-----------------------------------------------------------------------
  290. X    get_home_dir(home_dir):  leave plenty of room for result!
  291. X------------------------------------------------------------------------*/
  292. Xint
  293. Xget_home_dir(home_dir)
  294. Xchar *home_dir;
  295. X{
  296. Xstatic char home_directory[256] = "";
  297. Xstruct passwd *pwent;
  298. Xstruct passwd *getpwuid();
  299. X
  300. X    if(home_directory[0])
  301. X    {
  302. X        strcpy(home_dir,home_directory);
  303. X        return(0);
  304. X    }
  305. X
  306. X    if(!(pwent = getpwuid(getuid())))
  307. X    {
  308. X        perror("cannot get password entry for you!!");
  309. X        exit(255);
  310. X    }
  311. X    strcpy(home_directory,pwent->pw_dir);
  312. X    strcpy(home_dir,pwent->pw_dir);
  313. X    endpwent();
  314. X    return(0);
  315. X
  316. X}    /* end of get_home_dir */
  317. X
  318. X/*+-------------------------------------------------------------------------
  319. X    strlwr(str) - make all alpha chars in string lower case
  320. X--------------------------------------------------------------------------*/
  321. Xvoid
  322. Xstrlwr(str)
  323. Xregister char *str;
  324. X{
  325. X    while(*str)
  326. X    {
  327. X        if(isupper(*str))
  328. X            *str = tolower(*str);
  329. X        str++;
  330. X    }
  331. X
  332. X}    /* end of strlwr */
  333. X
  334. X/*+-------------------------------------------------------------------------
  335. X    xls_now(now) - get time of day in local STANDARD time in XLS units
  336. X--------------------------------------------------------------------------*/
  337. Xdouble
  338. Xxls_now(now)
  339. Xtime_t now;
  340. X{
  341. Xdouble xlsNow;
  342. X
  343. X#define EPOCH_DATE        25569    /* 1/1/70 Midnight in XLS units */
  344. X
  345. X    tzset();
  346. X    now -= timezone;
  347. X    xlsNow = (double)EPOCH_DATE + ((double)now / (double)86400.0);
  348. X    return(xlsNow);
  349. X
  350. X}    /* end of xls_now */
  351. X
  352. X/*+-------------------------------------------------------------------------
  353. X    make_brLABEL(str) - convert null terminated string to brLABEL
  354. Xcaller needs to plug rw, col and rgbAttr (they all contain 0 at return,
  355. Xexcept rgbAttr[0], which has rgbAttr0_fLocked set)
  356. X--------------------------------------------------------------------------*/
  357. XbrLABEL *
  358. Xmake_brLABEL(str)
  359. Xchar *str;
  360. X{
  361. Xregister int len = strlen(str);
  362. Xregister brLABEL *br = (brLABEL *)calloc(1,sizeof(brLABEL) + len - 1);
  363. X
  364. X    if(!br)
  365. X    {
  366. X        fprintf(stderr,"make_brLABEL: could not get memory for '%s'\n",str);
  367. X        return(br);
  368. X    }
  369. X
  370. X    br->type = btLABEL;
  371. X    br->length = sizeof(brLABEL) - sizeof(BHDR) + len - 1;
  372. X    br->cch = len;
  373. X    br->rgbAttr[0] = rgbAttr0_fLocked;
  374. X    memcpy((char *)br->rgch,str,(unsigned)len);
  375. X    return(br);
  376. X
  377. X}    /* end of make_brLABEL */
  378. X
  379. X/*+-------------------------------------------------------------------------
  380. X    make_brFONT(name,height,attr)
  381. X--------------------------------------------------------------------------*/
  382. XbrFONT *
  383. Xmake_brFONT(name,height,attr)
  384. Xchar *name;
  385. Xint height;
  386. Xint attr;
  387. X{
  388. Xregister int len = strlen(name);
  389. Xregister brFONT *br = (brFONT *)calloc(1,sizeof(brFONT) + len - 1);
  390. X
  391. X    if(!br)
  392. X    {
  393. X        fprintf(stderr,"make_brFONT: could not get memory for '%s'\n",name);
  394. X        return(br);
  395. X    }
  396. X
  397. X    br->type = btFONT;
  398. X    br->length = sizeof(brFONT) - sizeof(BHDR) + len - 1;
  399. X    br->dy = (UINT16)height;
  400. X    br->grbit = (UINT16)attr;
  401. X    br->cch = len;
  402. X    memcpy((char *)br->rgch,name,(unsigned)len);
  403. X    return(br);
  404. X
  405. X}    /* end of make_brFONT */
  406. X
  407. X/*+-------------------------------------------------------------------------
  408. X    make_brFORMAT(picture) - convert null terminated picture to brFORMAT
  409. X--------------------------------------------------------------------------*/
  410. XbrFORMAT *
  411. Xmake_brFORMAT(picture)
  412. Xchar *picture;
  413. X{
  414. Xregister int len = strlen(picture);
  415. Xregister brFORMAT *br = (brFORMAT *)calloc(1,sizeof(brFORMAT) + len - 1);
  416. X
  417. X    if(!br)
  418. X    {
  419. X        fprintf(stderr,"make_brFORMAT: could not get memory for '%s'\n",
  420. X            picture);
  421. X        return(br);
  422. X    }
  423. X
  424. X    br->type = btFORMAT;
  425. X    br->length = sizeof(brFORMAT) - sizeof(BHDR) + len - 1;
  426. X    br->cch = len;
  427. X    memcpy((char *)br->rgch,picture,(unsigned)len);
  428. X    return(br);
  429. X
  430. X}    /* end of make_brFORMAT */
  431. X
  432. X/*+-------------------------------------------------------------------------
  433. X    make_brNAME_cell(name,row,col)
  434. X--------------------------------------------------------------------------*/
  435. XbrNAME *
  436. Xmake_brNAME_cell(name,row,col)
  437. Xchar *name;
  438. Xint row;
  439. Xint col;
  440. X{
  441. Xregister int len = strlen(name);
  442. XopRefN *op;
  443. Xint len2 = sizeof(brNAME)-1+len + sizeof(*op) + 1;
  444. Xregister brNAME *br = (brNAME *)calloc(1,len2);
  445. X
  446. X    if(!br)
  447. X    {
  448. X        fprintf(stderr,"make_brNAME: could not get memory for '%s'\n",name);
  449. X        return(br);
  450. X    }
  451. X
  452. X    br->type = btNAME;
  453. X    br->length = len2 - sizeof(BHDR);
  454. X    br->cch = (UINT8)len;
  455. X    br->cce = (UINT8)sizeof(opRefN);
  456. X    memcpy((char *)br->rgch,name,(unsigned)len);
  457. X    op = (opRefN *)((char *)(br + 1) + len - 1);
  458. X    op->op = ptgRefN;
  459. X    op->grbitRw = (UINT16)row & 0x3FFF;
  460. X    op->col = (UINT8)col;
  461. X    *((char *)(op + 1)) = br->cce;
  462. X    return(br);
  463. X
  464. X}    /* end of make_brNAME_cell */
  465. X
  466. X/*+-------------------------------------------------------------------------
  467. X    make_brNAME_area(name,firstrow,firstcol,rows,cols)
  468. X--------------------------------------------------------------------------*/
  469. XbrNAME *
  470. Xmake_brNAME_area(name,firstrow,firstcol,rows,cols)
  471. Xchar *name;
  472. Xint firstrow;
  473. Xint firstcol;
  474. Xint rows;
  475. Xint cols;
  476. X{
  477. Xregister int len = strlen(name);
  478. XopAreaN *op;
  479. Xint len2 = sizeof(brNAME)-1+len + sizeof(*op) + 1;
  480. Xregister brNAME *br = (brNAME *)calloc(1,len2);
  481. X
  482. X    if(!br)
  483. X    {
  484. X        fprintf(stderr,"make_brNAME: could not get memory for '%s'\n",name);
  485. X        return(br);
  486. X    }
  487. X
  488. X    br->type = btNAME;
  489. X    br->length = len2 - sizeof(BHDR);
  490. X    br->cch = (UINT8)len;
  491. X    br->cce = (UINT8)sizeof(opAreaN);
  492. X    memcpy((char *)br->rgch,name,(unsigned)len);
  493. X    op = (opAreaN *)((char *)(br + 1) + len - 1);
  494. X    op->op = ptgAreaN;
  495. X    op->grbitRwFirst = (UINT16)firstrow & 0x3FFF;
  496. X    op->grbitRwLast = (op->grbitRwFirst + rows - 1) & 0x3FFF;
  497. X    op->colFirst = (UINT8)firstcol;
  498. X    op->colLast = (UINT8)firstcol + cols - 1;
  499. X    *((char *)(op + 1)) = br->cce;
  500. X    return(br);
  501. X
  502. X}    /* end of make_brNAME_area */
  503. X
  504. X/*+-------------------------------------------------------------------------
  505. X    xls_write_br(x,bhdr)
  506. X--------------------------------------------------------------------------*/
  507. Xlong
  508. Xxls_write_br(x,bhdr)
  509. XXLS_FILE *x;
  510. Xregister BHDR *bhdr;
  511. X{
  512. Xregister int len = bhdr->length + sizeof(BHDR);
  513. Xlong fpos = ftell(x->fp);
  514. X
  515. X    if(fwrite((char *)bhdr,1,len,x->fp) != len)
  516. X    {
  517. X        fprintf(stderr,"xls_write_br type=%d len=%d ",bhdr->type,len);
  518. X        perror(x->filename);
  519. X        return(-1);
  520. X    }
  521. X    return(fpos);
  522. X
  523. X}    /* end of xls_write_br */
  524. X
  525. X/*+-------------------------------------------------------------------------
  526. X    xls_get_brDIMENSION(x,handler)
  527. X--------------------------------------------------------------------------*/
  528. Xlong
  529. Xxls_get_brDIMENSION(x,dimension)
  530. XXLS_FILE *x;
  531. XbrDIMENSION *dimension;
  532. X{
  533. Xlong fpos;
  534. XUINT8 buf[2080];
  535. XBHDR *bhdr = (BHDR *)buf;
  536. X
  537. X    fseek(x->fp,0L,SEEK_SET);
  538. X    do 
  539. X    {
  540. X        fpos = ftell(x->fp);
  541. X        if(fread((char *)buf,1,sizeof(BHDR),x->fp) != sizeof(BHDR))
  542. X        {
  543. X            fprintf(stderr,"xls get dimension short read 1\n");
  544. X            return(-1);
  545. X        }
  546. X        if(fread((char *)buf + sizeof(BHDR),1,(size_t)bhdr->length,x->fp) !=
  547. X            (size_t)bhdr->length)
  548. X        {
  549. X            fprintf(stderr,"xls get dimension short read 2\n");
  550. X            return(-1);
  551. X        }
  552. X        if((bhdr->type == btDIMENSION) &&
  553. X            (bhdr->length == (sizeof(brDIMENSION) - sizeof(BHDR))))
  554. X        {
  555. X            memcpy((char *)dimension,(char *)bhdr,sizeof(brDIMENSION));
  556. X            return(fpos);
  557. X        }
  558. X    } while(bhdr->type != btEOF);
  559. X
  560. X    fprintf(stderr,"xls get dimension found none to get\n");
  561. X    return(-1);
  562. X
  563. X}    /* end of xls_get_brDIMENSION */
  564. X
  565. X/*+-------------------------------------------------------------------------
  566. X    xls_append(filename)
  567. X
  568. Xreturns -1 or next user data row number to write
  569. X--------------------------------------------------------------------------*/
  570. XXLS_FILE *
  571. Xxls_append(filename)
  572. Xchar *filename;
  573. X{
  574. XbrDIMENSION dimension;
  575. Xint row;
  576. XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
  577. X
  578. X    if(!x)
  579. X    {
  580. X        fprintf(stderr,"memory error\n");
  581. X        return((XLS_FILE *)0);
  582. X    }
  583. X
  584. X    strcpy(x->filename,filename);
  585. X    x->dimension_fpos = -1;
  586. X    x->first_data_row = LABEL_ROW + 1;
  587. X    x->last_data_row = -1;
  588. X
  589. X    if(!(x->fp = fopen(filename,"r+")))
  590. X    {
  591. X        fprintf(stderr,"xls_append could not open '%s'\n",filename);
  592. X        perror(filename);
  593. X        return((XLS_FILE *)0);
  594. X    }
  595. X
  596. X    if((x->dimension_fpos = xls_get_brDIMENSION(x,&dimension)) < 0)
  597. X    {
  598. X        fprintf(stderr,"xls_append thinks '%s' is corrupt\n",filename);
  599. X        perror(filename);
  600. X        fclose(x->fp);
  601. X        return((XLS_FILE *)0);
  602. X    }
  603. X
  604. X    if((row = dimension.rwMac - x->first_data_row) < 0)
  605. X    {
  606. X        fprintf(stderr,"xls_append unexpected next row in '%s'\n",filename);
  607. X        perror(filename);
  608. X        fclose(x->fp);
  609. X        return((XLS_FILE *)0);
  610. X    }
  611. X
  612. X    if(fseek(x->fp,-4L,SEEK_END))
  613. X    {
  614. X        fprintf(stderr,"xls_append could not seek on '%s'\n",filename);
  615. X        perror(filename);
  616. X        fclose(x->fp);
  617. X        return((XLS_FILE *)0);
  618. X    }
  619. X
  620. X    if(fgetc(x->fp) != btEOF)
  621. X    {
  622. X        fprintf(stderr,"xls_append found corrupt '%s'\n",filename);
  623. X        perror(filename);
  624. X        fclose(x->fp);
  625. X        return((XLS_FILE *)0);
  626. X    }
  627. X    fseek(x->fp,-4L,SEEK_END);
  628. X
  629. X    x->last_data_row = row;
  630. X    return(x);
  631. X
  632. X}    /* end of xls_append */
  633. X
  634. X/*+-------------------------------------------------------------------------
  635. X    xls_create_Rlog(filename)
  636. X--------------------------------------------------------------------------*/
  637. XXLS_FILE *
  638. Xxls_create_Rlog(filename)
  639. Xchar *filename;
  640. X{
  641. Xint err;
  642. XbrBOF bof;
  643. XbrCOLWIDTH cw;
  644. XbrDIMENSION dim;
  645. XbrFONT *font;
  646. XbrFORMAT *fmt;
  647. XbrFORMATCOUNT fc;
  648. XbrLABEL *label;
  649. XbrNAME *name;
  650. Xchar *sHEADER_fmt =
  651. X    "ECU Received File Log - created %02d-%02d-%04d %02d:%02d:%02d";
  652. Xchar *sDATE = "Date";
  653. Xchar *sFROM = "From";
  654. Xchar *sLENGTH = "Length";
  655. Xchar *sNAME = "Name";
  656. Xchar s80[80];
  657. Xtime_t now;
  658. Xstruct tm *lt;
  659. XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
  660. X
  661. X    if(!x)
  662. X    {
  663. X        fprintf(stderr,"memory error\n");
  664. X        return((XLS_FILE *)0);
  665. X    }
  666. X
  667. X    strcpy(x->filename,filename);
  668. X    x->dimension_fpos = -1;
  669. X    x->first_data_row = LABEL_ROW + 1;
  670. X    x->last_data_row = -1;
  671. X
  672. X    unlink(filename);
  673. X    if(!(x->fp = fopen(filename,"w+")))
  674. X    {
  675. X        fprintf(stderr,"xls_create_Rlog could not open '%s'\n",filename);
  676. X        perror(filename);
  677. X        free((char *)x);
  678. X        return((XLS_FILE *)0);
  679. X    }
  680. X
  681. X    chmod(filename,0644);    /* only writable by owner */
  682. X
  683. X    /* BOF */
  684. X    bof.type = btBOF;
  685. X    bof.length = sizeof(brBOF) - sizeof(BHDR);
  686. X    bof.vers = versExcel;
  687. X    bof.dt = dtWorksheet;
  688. X    if(xls_write_br(x,(BHDR *)&bof) < 0)
  689. X        goto ERROR_EXIT;
  690. X
  691. X    /* HELV 10 font */
  692. X    if(!(font = make_brFONT("Helv",200,0)))
  693. X        goto ERROR_EXIT;
  694. X    err = xls_write_br(x,(BHDR *)font) < 0;
  695. X    free((char *)font);
  696. X    if(err)
  697. X        goto ERROR_EXIT;
  698. X
  699. X    /* HELV 10 BOLD font */
  700. X    if(!(font = make_brFONT("Helv",200,fBold)))
  701. X        goto ERROR_EXIT;
  702. X    err = xls_write_br(x,(BHDR *)font) < 0;
  703. X    free((char *)font);
  704. X    if(err)
  705. X        goto ERROR_EXIT;
  706. X
  707. X    /* column 0 width */
  708. X    cw.type = btCOLWIDTH;
  709. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  710. X    cw.colFirst = Rlog_DATE_COL;        /* 1st col in range */
  711. X    cw.colLast = Rlog_DATE_COL;        /* last col in range */
  712. X    cw.dz = 3766;                /* column width */
  713. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  714. X        goto ERROR_EXIT;
  715. X
  716. X    /* column 1 width */
  717. X    cw.type = btCOLWIDTH;
  718. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  719. X    cw.colFirst = Rlog_FROM_COL;        /* 1st col in range */
  720. X    cw.colLast = Rlog_FROM_COL;        /* last col in range */
  721. X    cw.dz = 3766;                /* column width */
  722. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  723. X        goto ERROR_EXIT;
  724. X
  725. X    /* column 2 width */
  726. X    cw.type = btCOLWIDTH;
  727. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  728. X    cw.colFirst = Rlog_LENGTH_COL;    /* 1st col in range */
  729. X    cw.colLast = Rlog_LENGTH_COL;    /* last col in range */
  730. X    cw.dz = 2230;                /* column width */
  731. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  732. X        goto ERROR_EXIT;
  733. X
  734. X    /* column 3 width */
  735. X    cw.type = btCOLWIDTH;
  736. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  737. X    cw.colFirst = Rlog_NAME_COL;        /* 1st col in range */
  738. X    cw.colLast = Rlog_NAME_COL;        /* last col in range */
  739. X    cw.dz = 8374;                /* column width */
  740. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  741. X        goto ERROR_EXIT;
  742. X
  743. X    /* FORMATCOUNT */
  744. X    fc.type = btFORMATCOUNT;
  745. X    fc.length = sizeof(brFORMATCOUNT) - sizeof(BHDR);
  746. X    fc.FmtCount = FORMAT_COUNT;
  747. X    if(xls_write_br(x,(BHDR *)&fc) < 0)
  748. X        goto ERROR_EXIT;
  749. X
  750. X    /* "General" FORMAT */
  751. X    if(!(fmt = make_brFORMAT("General")))
  752. X        goto ERROR_EXIT;
  753. X    err = xls_write_br(x,(BHDR *)fmt) < 0;
  754. X    free((char *)fmt);
  755. X    if(err)
  756. X        goto ERROR_EXIT;
  757. X
  758. X    /* date FORMAT */
  759. X    if(!(fmt = make_brFORMAT("yyyy-mm-dd hh:mm")))
  760. X        goto ERROR_EXIT;
  761. X    err = xls_write_br(x,(BHDR *)fmt) < 0;
  762. X    free((char *)fmt);
  763. X    if(err)
  764. X        goto ERROR_EXIT;
  765. X
  766. X    /* "DATE" NAME */
  767. X    if(!(name = make_brNAME_area(sDATE,x->first_data_row,Rlog_DATE_COL,
  768. X            TOTAL_DATA_ROWS,1)))
  769. X    {
  770. X        goto ERROR_EXIT;
  771. X    }
  772. X    err = xls_write_br(x,(BHDR *)name) < 0;
  773. X    free((char *)name);
  774. X    if(err)
  775. X        goto ERROR_EXIT;
  776. X
  777. X    /* "FROM" NAME */
  778. X    if(!(name = make_brNAME_area(sFROM,x->first_data_row,Rlog_FROM_COL,
  779. X            TOTAL_DATA_ROWS,1)))
  780. X    {
  781. X        goto ERROR_EXIT;
  782. X    }
  783. X    err = xls_write_br(x,(BHDR *)name) < 0;
  784. X    free((char *)name);
  785. X    if(err)
  786. X        goto ERROR_EXIT;
  787. X
  788. X    /* "LENGTH" NAME */
  789. X    if(!(name = make_brNAME_area(sLENGTH,x->first_data_row,Rlog_LENGTH_COL,
  790. X            TOTAL_DATA_ROWS,1)))
  791. X    {
  792. X        goto ERROR_EXIT;
  793. X    }
  794. X    err = xls_write_br(x,(BHDR *)name) < 0;
  795. X    free((char *)name);
  796. X    if(err)
  797. X        goto ERROR_EXIT;
  798. X
  799. X    /* "NAME" NAME */
  800. X    if(!(name = make_brNAME_area(sNAME,x->first_data_row,Rlog_NAME_COL,
  801. X            TOTAL_DATA_ROWS,1)))
  802. X    {
  803. X        goto ERROR_EXIT;
  804. X    }
  805. X    err = xls_write_br(x,(BHDR *)name) < 0;
  806. X    free((char *)name);
  807. X    if(err)
  808. X        goto ERROR_EXIT;
  809. X
  810. X    /* DIMENSION */
  811. X    dim.type = btDIMENSION;
  812. X    dim.length = sizeof(brDIMENSION) - sizeof(BHDR);
  813. X    dim.rwMic = 0;                /* first defined row */
  814. X    dim.rwMac = x->first_data_row;    /* last row + 1 */
  815. X    dim.colMic = 0;                /* first col */
  816. X    dim.colMac = 4;                /* last row + 1 */
  817. X    if((x->dimension_fpos = xls_write_br(x,(BHDR *)&dim)) < 0)
  818. X        goto ERROR_EXIT;
  819. X
  820. X    /* HEADER */
  821. X    time(&now);
  822. X    lt = localtime(&now);
  823. X    sprintf(s80,sHEADER_fmt,
  824. X        lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  825. X        lt->tm_hour,lt->tm_min,lt->tm_sec);
  826. X    if(!(label = make_brLABEL(s80)))
  827. X        goto ERROR_EXIT;
  828. X    label->rw = HEADER_ROW;
  829. X    label->col = HEADER_COL;
  830. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  831. X    err = xls_write_br(x,(BHDR *)label) < 0;
  832. X    free((char *)label);
  833. X    if(err)
  834. X        goto ERROR_EXIT;
  835. X
  836. X    /* DATE */
  837. X    if(!(label = make_brLABEL(sDATE)))
  838. X        goto ERROR_EXIT;
  839. X    label->rw = LABEL_ROW;
  840. X    label->col = Rlog_DATE_COL;
  841. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  842. X    label->rgbAttr[2] = alc_LEFT;
  843. X    err = xls_write_br(x,(BHDR *)label) < 0;
  844. X    free((char *)label);
  845. X    if(err)
  846. X        goto ERROR_EXIT;
  847. X
  848. X    /* FROM */
  849. X    if(!(label = make_brLABEL(sFROM)))
  850. X        goto ERROR_EXIT;
  851. X    label->rw = LABEL_ROW;
  852. X    label->col = Rlog_FROM_COL;
  853. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  854. X    label->rgbAttr[2] = alc_LEFT;
  855. X    err = xls_write_br(x,(BHDR *)label) < 0;
  856. X    free((char *)label);
  857. X    if(err)
  858. X        goto ERROR_EXIT;
  859. X
  860. X    /* LENGTH */
  861. X    if(!(label = make_brLABEL(sLENGTH)))
  862. X        goto ERROR_EXIT;
  863. X    label->rw = LABEL_ROW;
  864. X    label->col = Rlog_LENGTH_COL;
  865. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  866. X    label->rgbAttr[2] = alc_LEFT;
  867. X    err = xls_write_br(x,(BHDR *)label) < 0;
  868. X    free((char *)label);
  869. X    if(err)
  870. X        goto ERROR_EXIT;
  871. X
  872. X    /* NAME */
  873. X    if(!(label = make_brLABEL(sNAME)))
  874. X        goto ERROR_EXIT;
  875. X    label->rw = LABEL_ROW;
  876. X    label->col = Rlog_NAME_COL;
  877. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  878. X    label->rgbAttr[2] = alc_LEFT;
  879. X    err = xls_write_br(x,(BHDR *)label) < 0;
  880. X    free((char *)label);
  881. X    if(err)
  882. X        goto ERROR_EXIT;
  883. X
  884. X    return(x);
  885. X
  886. XERROR_EXIT:
  887. X    fprintf(stderr,"xls_create_Rlog of '%s' aborted due to error\n",filename);
  888. X    fclose(x->fp);
  889. X    unlink(filename);
  890. X    free((char *)x);
  891. X    return((XLS_FILE *)0);
  892. X
  893. X}    /* end of xls_create_Rlog */
  894. X
  895. X/*+-------------------------------------------------------------------------
  896. X    xls_write_Rlog_record(x,row,date,from,length,name)
  897. X
  898. X  returns file position of written record or -1 if error
  899. X--------------------------------------------------------------------------*/
  900. Xlong
  901. Xxls_write_Rlog_record(x,row,date,from,length,name)
  902. XXLS_FILE *x;
  903. Xint row;
  904. Xchar *date;
  905. Xchar *from;
  906. Xlong length;
  907. Xchar *name;
  908. X{
  909. XbrNUMBER num;
  910. XbrLABEL *label;
  911. Xlong fpos = ftell(x->fp);
  912. Xint err;
  913. X
  914. X    /* DATE */
  915. X    if(!(label = make_brLABEL(date)))
  916. X        return(-1);
  917. X    label->rw = x->first_data_row + row;
  918. X    label->col = Rlog_DATE_COL;
  919. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  920. X    err = xls_write_br(x,(BHDR *)label) < 0;
  921. X    free((char *)label);
  922. X    if(err)
  923. X        return(-1);
  924. X
  925. X    /* FROM */
  926. X    if(!(label = make_brLABEL(from)))
  927. X        return(-1);
  928. X    label->rw = x->first_data_row + row;
  929. X    label->col = Rlog_FROM_COL;
  930. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  931. X    err = xls_write_br(x,(BHDR *)label) < 0;
  932. X    free((char *)label);
  933. X    if(err)
  934. X        return(-1);
  935. X
  936. X    /* LENGTH */
  937. X    num.type = btNUMBER;
  938. X    num.length = sizeof(brNUMBER) - sizeof(BHDR);
  939. X    num.rw = x->first_data_row + row;
  940. X    num.col = Rlog_LENGTH_COL;
  941. X    num.num = (double)length;
  942. X    num.rgbAttr[0] = rgbAttr0_fLocked;
  943. X    num.rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  944. X    num.rgbAttr[2] = 0;
  945. X    if(xls_write_br(x,(BHDR *)&num) < 0)
  946. X        return(-1);
  947. X
  948. X    /* NAME */
  949. X    if(!(label = make_brLABEL(name)))
  950. X        return(-1);
  951. X    label->rw = x->first_data_row + row;
  952. X    label->col = Rlog_NAME_COL;
  953. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  954. X    err = xls_write_br(x,(BHDR *)label) < 0;
  955. X    free((char *)label);
  956. X    if(err)
  957. X        return(-1);
  958. X
  959. X    x->last_data_row = row;
  960. X
  961. X    return(fpos);
  962. X
  963. X}    /* end of xls_write_Rlog_record */
  964. X
  965. X/*+-------------------------------------------------------------------------
  966. X    xls_create_Clog(filename)
  967. X--------------------------------------------------------------------------*/
  968. XXLS_FILE *
  969. Xxls_create_Clog(filename)
  970. Xchar *filename;
  971. X{
  972. Xint err;
  973. XbrBOF bof;
  974. XbrCOLWIDTH cw;
  975. XbrDIMENSION dim;
  976. XbrFONT *font;
  977. XbrFORMAT *fmt;
  978. XbrFORMATCOUNT fc;
  979. XbrLABEL *label;
  980. XbrNAME *name;
  981. Xchar *sHEADER_fmt =
  982. X    "ECU Connection Log - created %02d-%02d-%04d %02d:%02d:%02d";
  983. Xchar *sDATE = "Date";
  984. Xchar *sSYS = "System";
  985. Xchar *sPHONE = "Phone";
  986. Xchar *sTIME = "Time";
  987. Xchar s80[80];
  988. Xtime_t now;
  989. Xstruct tm *lt;
  990. XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
  991. X
  992. X    if(!x)
  993. X    {
  994. X        fprintf(stderr,"memory error\n");
  995. X        return((XLS_FILE *)0);
  996. X    }
  997. X
  998. X    strcpy(x->filename,filename);
  999. X    x->dimension_fpos = -1;
  1000. X    x->first_data_row = LABEL_ROW + 1;
  1001. X    x->last_data_row = -1;
  1002. X
  1003. X    unlink(filename);
  1004. X    if(!(x->fp = fopen(filename,"w+")))
  1005. X    {
  1006. X        fprintf(stderr,"xls_create_Clog could not open '%s'\n",filename);
  1007. X        perror(filename);
  1008. X        free((char *)x);
  1009. X        return((XLS_FILE *)0);
  1010. X    }
  1011. X
  1012. X    chmod(filename,0644);    /* only writable by owner */
  1013. X
  1014. X    /* BOF */
  1015. X    bof.type = btBOF;
  1016. X    bof.length = sizeof(brBOF) - sizeof(BHDR);
  1017. X    bof.vers = versExcel;
  1018. X    bof.dt = dtWorksheet;
  1019. X    if(xls_write_br(x,(BHDR *)&bof) < 0)
  1020. X        goto ERROR_EXIT;
  1021. X
  1022. X    /* HELV 10 font */
  1023. X    if(!(font = make_brFONT("Helv",200,0)))
  1024. X        goto ERROR_EXIT;
  1025. X    err = xls_write_br(x,(BHDR *)font) < 0;
  1026. X    free((char *)font);
  1027. X    if(err)
  1028. X        goto ERROR_EXIT;
  1029. X
  1030. X    /* HELV 10 BOLD font */
  1031. X    if(!(font = make_brFONT("Helv",200,fBold)))
  1032. X        goto ERROR_EXIT;
  1033. X    err = xls_write_br(x,(BHDR *)font) < 0;
  1034. X    free((char *)font);
  1035. X    if(err)
  1036. X        goto ERROR_EXIT;
  1037. X
  1038. X    /* column 0 width */
  1039. X    cw.type = btCOLWIDTH;
  1040. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  1041. X    cw.colFirst = Clog_DATE_COL;        /* 1st col in range */
  1042. X    cw.colLast = Clog_DATE_COL;        /* last col in range */
  1043. X    cw.dz = 3766;                /* column width */
  1044. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  1045. X        goto ERROR_EXIT;
  1046. X
  1047. X    /* column 1 width */
  1048. X    cw.type = btCOLWIDTH;
  1049. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  1050. X    cw.colFirst = Clog_SYS_COL;        /* 1st col in range */
  1051. X    cw.colLast = Clog_SYS_COL;        /* last col in range */
  1052. X    cw.dz = 3766;                /* column width */
  1053. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  1054. X        goto ERROR_EXIT;
  1055. X
  1056. X    /* column 2 width */
  1057. X    cw.type = btCOLWIDTH;
  1058. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  1059. X    cw.colFirst = Clog_PHONE_COL;    /* 1st col in range */
  1060. X    cw.colLast = Clog_PHONE_COL;    /* last col in range */
  1061. X    cw.dz = 3766;                /* column width */
  1062. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  1063. X        goto ERROR_EXIT;
  1064. X
  1065. X    /* column 3 width */
  1066. X    cw.type = btCOLWIDTH;
  1067. X    cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
  1068. X    cw.colFirst = Clog_TIME_COL;        /* 1st col in range */
  1069. X    cw.colLast = Clog_TIME_COL;        /* last col in range */
  1070. X    cw.dz = 1974;                /* column width */
  1071. X    if(xls_write_br(x,(BHDR *)&cw) < 0)
  1072. X        goto ERROR_EXIT;
  1073. X
  1074. X    /* FORMATCOUNT */
  1075. X    fc.type = btFORMATCOUNT;
  1076. X    fc.length = sizeof(brFORMATCOUNT) - sizeof(BHDR);
  1077. X    fc.FmtCount = FORMAT_COUNT;
  1078. X    if(xls_write_br(x,(BHDR *)&fc) < 0)
  1079. X        goto ERROR_EXIT;
  1080. X
  1081. X    /* "General" FORMAT */
  1082. X    if(!(fmt = make_brFORMAT("General")))
  1083. X        goto ERROR_EXIT;
  1084. X    err = xls_write_br(x,(BHDR *)fmt) < 0;
  1085. X    free((char *)fmt);
  1086. X    if(err)
  1087. X        goto ERROR_EXIT;
  1088. X
  1089. X    /* time FORMAT */
  1090. X    if(!(fmt = make_brFORMAT("hh:mm:ss")))    /* Clog_FORMAT_TIME */
  1091. X        goto ERROR_EXIT;
  1092. X    err = xls_write_br(x,(BHDR *)fmt) < 0;
  1093. X    free((char *)fmt);
  1094. X    if(err)
  1095. X        goto ERROR_EXIT;
  1096. X
  1097. X    /* "DATE" NAME */
  1098. X    if(!(name = make_brNAME_area(sDATE,x->first_data_row,Clog_DATE_COL,
  1099. X            TOTAL_DATA_ROWS,1)))
  1100. X    {
  1101. X        goto ERROR_EXIT;
  1102. X    }
  1103. X    err = xls_write_br(x,(BHDR *)name) < 0;
  1104. X    free((char *)name);
  1105. X    if(err)
  1106. X        goto ERROR_EXIT;
  1107. X
  1108. X    /* "SYS" NAME */
  1109. X    if(!(name = make_brNAME_area(sSYS,x->first_data_row,Clog_SYS_COL,
  1110. X            TOTAL_DATA_ROWS,1)))
  1111. X    {
  1112. X        goto ERROR_EXIT;
  1113. X    }
  1114. X    err = xls_write_br(x,(BHDR *)name) < 0;
  1115. X    free((char *)name);
  1116. X    if(err)
  1117. X        goto ERROR_EXIT;
  1118. X
  1119. X    /* "PHONE" NAME */
  1120. X    if(!(name = make_brNAME_area(sPHONE,x->first_data_row,Clog_PHONE_COL,
  1121. X            TOTAL_DATA_ROWS,1)))
  1122. X    {
  1123. X        goto ERROR_EXIT;
  1124. X    }
  1125. X    err = xls_write_br(x,(BHDR *)name) < 0;
  1126. X    free((char *)name);
  1127. X    if(err)
  1128. X        goto ERROR_EXIT;
  1129. X
  1130. X    /* "TIME" NAME */
  1131. X    if(!(name = make_brNAME_area(sTIME,x->first_data_row,Clog_TIME_COL,
  1132. X            TOTAL_DATA_ROWS,1)))
  1133. X    {
  1134. X        goto ERROR_EXIT;
  1135. X    }
  1136. X    err = xls_write_br(x,(BHDR *)name) < 0;
  1137. X    free((char *)name);
  1138. X    if(err)
  1139. X        goto ERROR_EXIT;
  1140. X
  1141. X    /* DIMENSION */
  1142. X    dim.type = btDIMENSION;
  1143. X    dim.length = sizeof(brDIMENSION) - sizeof(BHDR);
  1144. X    dim.rwMic = 0;                /* first defined row */
  1145. X    dim.rwMac = x->first_data_row;    /* last row + 1 */
  1146. X    dim.colMic = 0;                /* first col */
  1147. X    dim.colMac = 4;                /* last row + 1 */
  1148. X    if((x->dimension_fpos = xls_write_br(x,(BHDR *)&dim)) < 0)
  1149. X        goto ERROR_EXIT;
  1150. X
  1151. X    /* HEADER */
  1152. X    time(&now);
  1153. X    lt = localtime(&now);
  1154. X    sprintf(s80,sHEADER_fmt,
  1155. X        lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  1156. X        lt->tm_hour,lt->tm_min,lt->tm_sec);
  1157. X    if(!(label = make_brLABEL(s80)))
  1158. X        goto ERROR_EXIT;
  1159. X    label->rw = HEADER_ROW;
  1160. X    label->col = HEADER_COL;
  1161. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  1162. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1163. X    free((char *)label);
  1164. X    if(err)
  1165. X        goto ERROR_EXIT;
  1166. X
  1167. X    /* DATE */
  1168. X    if(!(label = make_brLABEL(sDATE)))
  1169. X        goto ERROR_EXIT;
  1170. X    label->rw = LABEL_ROW;
  1171. X    label->col = Clog_DATE_COL;
  1172. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  1173. X    label->rgbAttr[2] = alc_LEFT;
  1174. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1175. X    free((char *)label);
  1176. X    if(err)
  1177. X        goto ERROR_EXIT;
  1178. X
  1179. X    /* SYS */
  1180. X    if(!(label = make_brLABEL(sSYS)))
  1181. X        goto ERROR_EXIT;
  1182. X    label->rw = LABEL_ROW;
  1183. X    label->col = Clog_SYS_COL;
  1184. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  1185. X    label->rgbAttr[2] = alc_LEFT;
  1186. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1187. X    free((char *)label);
  1188. X    if(err)
  1189. X        goto ERROR_EXIT;
  1190. X
  1191. X    /* PHONE */
  1192. X    if(!(label = make_brLABEL(sPHONE)))
  1193. X        goto ERROR_EXIT;
  1194. X    label->rw = LABEL_ROW;
  1195. X    label->col = Clog_PHONE_COL;
  1196. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  1197. X    label->rgbAttr[2] = alc_LEFT;
  1198. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1199. X    free((char *)label);
  1200. X    if(err)
  1201. X        goto ERROR_EXIT;
  1202. X
  1203. X    /* TIME */
  1204. X    if(!(label = make_brLABEL(sTIME)))
  1205. X        goto ERROR_EXIT;
  1206. X    label->rw = LABEL_ROW;
  1207. X    label->col = Clog_TIME_COL;
  1208. X    label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
  1209. X    label->rgbAttr[2] = alc_LEFT;
  1210. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1211. X    free((char *)label);
  1212. X    if(err)
  1213. X        goto ERROR_EXIT;
  1214. X
  1215. X    return(x);
  1216. X
  1217. XERROR_EXIT:
  1218. X    fprintf(stderr,"xls_create_Clog of '%s' aborted due to error\n",filename);
  1219. X    fclose(x->fp);
  1220. X    unlink(filename);
  1221. X    free((char *)x);
  1222. X    return((XLS_FILE *)0);
  1223. X
  1224. X}    /* end of xls_create_Clog */
  1225. X
  1226. X/*+-------------------------------------------------------------------------
  1227. X    xls_write_Clog_record(x,row,date,sys,secs)
  1228. X
  1229. X  returns file position of written record or -1 if error
  1230. X--------------------------------------------------------------------------*/
  1231. Xlong
  1232. Xxls_write_Clog_record(x,row,date,sys,phone,secs)
  1233. XXLS_FILE *x;
  1234. Xint row;
  1235. Xchar *date;
  1236. Xchar *sys;
  1237. Xchar *phone;
  1238. Xlong secs;
  1239. X{
  1240. XbrNUMBER num;
  1241. XbrLABEL *label;
  1242. Xlong fpos = ftell(x->fp);
  1243. Xint err;
  1244. X
  1245. X    /* DATE */
  1246. X    if(!(label = make_brLABEL(date)))
  1247. X        return(-1);
  1248. X    label->rw = x->first_data_row + row;
  1249. X    label->col = Clog_DATE_COL;
  1250. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  1251. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1252. X    free((char *)label);
  1253. X    if(err)
  1254. X        return(-1);
  1255. X
  1256. X    /* SYS */
  1257. X    if(!(label = make_brLABEL(sys)))
  1258. X        return(-1);
  1259. X    label->rw = x->first_data_row + row;
  1260. X    label->col = Clog_SYS_COL;
  1261. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  1262. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1263. X    free((char *)label);
  1264. X    if(err)
  1265. X        return(-1);
  1266. X
  1267. X    /* PHONE */
  1268. X    if(!(label = make_brLABEL(phone)))
  1269. X        return(-1);
  1270. X    label->rw = x->first_data_row + row;
  1271. X    label->col = Clog_PHONE_COL;
  1272. X    label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
  1273. X    err = xls_write_br(x,(BHDR *)label) < 0;
  1274. X    free((char *)label);
  1275. X    if(err)
  1276. X        return(-1);
  1277. X
  1278. X    /* TIME */
  1279. X    num.type = btNUMBER;
  1280. X    num.length = sizeof(brNUMBER) - sizeof(BHDR);
  1281. X    num.rw = x->first_data_row + row;
  1282. X    num.col = Clog_TIME_COL;
  1283. X    num.num = (double)secs / (3600.0 * 24.0);
  1284. X    num.rgbAttr[0] = rgbAttr0_fLocked;
  1285. X    num.rgbAttr[1] = (FONT_HELV10 << 6) | Clog_FORMAT_TIME;
  1286. X    num.rgbAttr[2] = 0;
  1287. X    if(xls_write_br(x,(BHDR *)&num) < 0)
  1288. X        return(-1);
  1289. X
  1290. X    x->last_data_row = row;
  1291. X
  1292. X    return(fpos);
  1293. X
  1294. X}    /* end of xls_write_Clog_record */
  1295. X
  1296. X/*+-------------------------------------------------------------------------
  1297. X    xls_write_eof_and_close(x)
  1298. X--------------------------------------------------------------------------*/
  1299. Xvoid
  1300. Xxls_write_eof_and_close(x)
  1301. XXLS_FILE *x;
  1302. X{
  1303. XbrDIMENSION dimension;
  1304. X
  1305. X    if(!x->fp)
  1306. X    {
  1307. X        fprintf(stderr,"xls_write_and_close: no file open!\n");
  1308. X        return;
  1309. X    }
  1310. X
  1311. X    fputc(btEOF,x->fp);
  1312. X    fputc(0,x->fp);
  1313. X    fputc(0,x->fp);
  1314. X    fputc(0,x->fp);
  1315. X
  1316. X    if(x->last_data_row >= 0)
  1317. X    {
  1318. X         if(x->dimension_fpos >= 0)
  1319. X        {
  1320. X            memset((char *)&dimension,0,sizeof(brDIMENSION));
  1321. X            errno = 0;
  1322. X            if(fseek(x->fp,x->dimension_fpos,SEEK_SET))
  1323. X                perror("xls_write_eof_and_close seek 1 error");
  1324. X            else if(fread((char *)&dimension,1,sizeof(brDIMENSION),x->fp) !=
  1325. X                sizeof(brDIMENSION))
  1326. X            {
  1327. X                perror("xls_write_eof_and_close dim read error");
  1328. X            }
  1329. X            dimension.rwMac = ++x->last_data_row +
  1330. X                x->first_data_row;
  1331. X            if(dimension.type == btDIMENSION)
  1332. X            {
  1333. X                if(fseek(x->fp,x->dimension_fpos,SEEK_SET))
  1334. X                    perror("xls_write_eof_and_close seek 2 error");
  1335. X                else if(fwrite((char *)&dimension,1,
  1336. X                        sizeof(brDIMENSION),x->fp) != sizeof(brDIMENSION))
  1337. X                {
  1338. X                    perror("xls_write_eof_and_close dim write error");
  1339. X                }
  1340. X            }
  1341. X            else
  1342. X                fprintf(stderr,"xls_write_eof_and_close dim write fail\n");
  1343. X        }
  1344. X        else
  1345. X            fprintf(stderr,"xls_write_eof_and_close no dim fpos\n");
  1346. X    }
  1347. X    else
  1348. X        fprintf(stderr,"xls_write_eof_and_close no last row\n");
  1349. X    x->last_data_row = -1;
  1350. X    x->dimension_fpos = -1;
  1351. X
  1352. X    fclose(x->fp);
  1353. X    x->fp = (FILE *)0;
  1354. X
  1355. X}    /* end of xls_write_eof_and_close */
  1356. X
  1357. X/*+-------------------------------------------------------------------------
  1358. X    rearranged_date(date)
  1359. X
  1360. X0000000000111111
  1361. X0123456789012345
  1362. X12-28-1990-17:08
  1363. X1990-12-28 17:08
  1364. X--------------------------------------------------------------------------*/
  1365. Xchar *
  1366. Xrearranged_date(date)
  1367. Xchar *date;
  1368. X{
  1369. Xstatic char rd[] = "####-##-## ##:##";
  1370. X
  1371. X    memcpy(rd +  0,date +  6,4);
  1372. X    memcpy(rd +  5,date +  0,5);
  1373. X    memcpy(rd + 11,date + 11,5);
  1374. X    return(rd);
  1375. X
  1376. X}    /* end of rearranged_date */
  1377. X
  1378. X/*+-------------------------------------------------------------------------
  1379. X    log_connect(logbuf)
  1380. X
  1381. X00000000001111111111222222222233
  1382. X01234567890123456789012345678901
  1383. X12-28-1990-17:06-01455-CONNECT tridom (426-0624) 9600 baud
  1384. X--------------------------------------------------------------------------*/
  1385. Xvoid
  1386. Xlog_connect(logbuf)
  1387. Xchar *logbuf;
  1388. X{
  1389. Xchar *sys = logbuf + 31;
  1390. Xint pid = atoi(logbuf + 17);
  1391. XCE *ce = ce_list_search(pid);
  1392. Xchar *cptr;
  1393. X
  1394. X    if(ce)
  1395. X    {
  1396. X        fprintf(stderr,"warning: connect to %s pid %d without disconnect\n",
  1397. X            ce->sys,pid);
  1398. X        ce_list_remove(ce);
  1399. X        free((char *)ce);
  1400. X    }
  1401. X
  1402. X    if(!(ce = (CE *)malloc(sizeof(CE))))
  1403. X    {
  1404. X        fprintf(stderr,"memory allocation error\n");
  1405. X        exit(250);
  1406. X    }
  1407. X
  1408. X    if(cptr = strchr(sys,' '))
  1409. X        *cptr = 0;
  1410. X
  1411. X    strncpy(ce->sys,sys,sizeof(ce->sys));
  1412. X    ce->sys[sizeof(ce->sys) - 1] = 0;
  1413. X    strcpy(ce->date,rearranged_date(logbuf));
  1414. X    ce->pid = pid;
  1415. X    ce_list_add(ce);
  1416. X
  1417. X}    /* end of log_connect */
  1418. X
  1419. X/*+-------------------------------------------------------------------------
  1420. X    log_disconnect(x,logbuf)
  1421. X
  1422. X00000000001111111111222222222233333
  1423. X01234567890123456789012345678901234
  1424. X12-28-1990-17:08-01455-DISCONNECT tridom (426-0624) 144 00:02:24
  1425. X--------------------------------------------------------------------------*/
  1426. Xlog_disconnect(x,logbuf)
  1427. XXLS_FILE *x;
  1428. Xchar *logbuf;
  1429. X{
  1430. Xchar *cptr;
  1431. Xchar date[128];
  1432. Xint pid = atoi(logbuf + 17);
  1433. XCE *ce = ce_list_search(pid);
  1434. Xchar *sys = logbuf + 34;
  1435. Xlong secs = 0L;
  1436. Xchar *phone = "";
  1437. X
  1438. X    if(cptr = strchr(sys,' '))
  1439. X    {
  1440. X        *cptr = 0;
  1441. X        cptr += 2;
  1442. X        phone = cptr;
  1443. X        if(cptr = strrchr(phone,')'))
  1444. X        {
  1445. X            *cptr = 0;
  1446. X            cptr++;
  1447. X            secs = atol(cptr);
  1448. X        }
  1449. X    }
  1450. X
  1451. X    if(ce)
  1452. X    {
  1453. X        strcpy(date,ce->date);
  1454. X        if(strcmp(ce->sys,sys))
  1455. X        {
  1456. X            fprintf(stderr,
  1457. X                "warning: system mismatch conn(%s) != disc(%s) pid %d\n",
  1458. X                ce->sys,sys,pid);
  1459. X        }
  1460. X        ce_list_remove(ce);
  1461. X        free((char *)ce);
  1462. X    }
  1463. X    else
  1464. X        strcpy(date,rearranged_date(logbuf));
  1465. X
  1466. X    xls_write_Clog_record(x,++x->last_data_row,date,sys,phone,secs);
  1467. X
  1468. X}    /* end of log_disconnect */
  1469. X
  1470. X/*+-------------------------------------------------------------------------
  1471. X    log_receive(x,logbuf)
  1472. X
  1473. X00000000001111111111222222222233333333334
  1474. X01234567890123456789012345678901234567890
  1475. X12-28-1990-17:08-01455-RECEIVE success: mbox (8016 bytes)
  1476. X--------------------------------------------------------------------------*/
  1477. Xvoid
  1478. Xlog_receive(x,logbuf)
  1479. XXLS_FILE *x;
  1480. Xchar *logbuf;
  1481. X{
  1482. Xchar *cptr;
  1483. Xchar *date = rearranged_date(logbuf);
  1484. Xint pid = atoi(logbuf + 17);
  1485. XCE *ce = ce_list_search(pid);
  1486. Xchar *from = (ce) ? ce->sys : "??";
  1487. Xlong length = 0L;
  1488. Xchar *name = logbuf + 40;
  1489. X
  1490. X    if(cptr = strchr(name,' '))
  1491. X    {
  1492. X        *cptr = 0;
  1493. X        cptr += 2;
  1494. X        length = atol(cptr);
  1495. X    }
  1496. X    xls_write_Rlog_record(x,++x->last_data_row,date,from,length,name);
  1497. X
  1498. X}    /* end of log_receive */
  1499. X
  1500. X/*+-------------------------------------------------------------------------
  1501. X    main(argc,argv)
  1502. X
  1503. X000000000011111111112222
  1504. X012345678901234567890123
  1505. X12-28-1990-17:06-01455-CONNECT tridom (426-0624) 9600 baud
  1506. X12-28-1990-17:08-01455-RECEIVE success: mbox (8016 bytes)
  1507. X12-28-1990-17:08-01455-DISCONNECT tridom (426-0624) 144 00:02:24
  1508. X--------------------------------------------------------------------------*/
  1509. Xmain(argc,argv)
  1510. Xint argc;
  1511. Xchar **argv;
  1512. X{
  1513. Xint itmp;
  1514. Xint row;
  1515. Xint errflg = 0;
  1516. Xdouble Biffdate;
  1517. Xdouble Avg;
  1518. Xdouble Min;
  1519. Xdouble Max;
  1520. Xint Sampq;
  1521. Xchar *fnRlog = "ecurlog.xls";
  1522. XXLS_FILE *xRlog;
  1523. Xchar *fnClog = "ecuclog.xls";
  1524. XXLS_FILE *xClog;
  1525. XFILE *fp_log;
  1526. Xchar logname[256];
  1527. Xchar logbuf[256];
  1528. XCE *tce;
  1529. Xextern char *optarg;
  1530. Xextern int optind;
  1531. X
  1532. X    logname[0] = 0;
  1533. X
  1534. X    while((itmp = getopt(argc,argv,"l:")) != -1)
  1535. X    {
  1536. X        switch(itmp)
  1537. X        {
  1538. X            case 'l':
  1539. X                strcpy(logname,optarg);
  1540. X                break;
  1541. X            case '?':
  1542. X                errflg++;
  1543. X                break;
  1544. X        }
  1545. X    }
  1546. X
  1547. X    if(errflg)
  1548. X    {
  1549. X        (void)fprintf(stderr,"usage: ecuxls [-l logfile]\n");
  1550. X        (void)fprintf(stderr,"default log file is ~/.ecu/log\n");
  1551. X        exit(254);
  1552. X    }
  1553. X
  1554. X    if(!logname[0])
  1555. X    {
  1556. X        get_home_dir(logname);
  1557. X        strcat(logname,"/.ecu/log");
  1558. X    }
  1559. X
  1560. X    fprintf(stderr,"ecuxls %s: %s -> (ecurlog.xls,ecuclog.xls)\n",
  1561. X        revision,logname);
  1562. X
  1563. X    if(!(fp_log = fopen(logname,"r")))
  1564. X    {
  1565. X        perror(logname);
  1566. X        exit(1);
  1567. X    }
  1568. X    if(!(xRlog = xls_create_Rlog(fnRlog)))
  1569. X    {
  1570. X        perror(fnRlog);
  1571. X        exit(2);
  1572. X    }
  1573. X    if(!(xClog = xls_create_Clog(fnClog)))
  1574. X    {
  1575. X        perror(fnClog);
  1576. X        exit(2);
  1577. X    }
  1578. X
  1579. X    while(fgets(logbuf,sizeof(logbuf),fp_log))
  1580. X    {
  1581. X        logbuf[strlen(logbuf) - 1] = 0;
  1582. X        if(!strncmp(logbuf + 23,"RECEIVE success",15))
  1583. X            log_receive(xRlog,logbuf);
  1584. X        else if(!strncmp(logbuf + 23,"CONNECT",7))
  1585. X            log_connect(logbuf);
  1586. X        else if(!strncmp(logbuf + 23,"DISCONNECT",10))
  1587. X            log_disconnect(xClog,logbuf);
  1588. X    }
  1589. X
  1590. X    xls_write_eof_and_close(xRlog);
  1591. X    xls_write_eof_and_close(xClog);
  1592. X    fclose(fp_log);
  1593. X
  1594. X    tce = ce_list_head;
  1595. X    while(tce)
  1596. X    {
  1597. X        fprintf(stderr,"warning: connect to %s pid %d without disconnect\n",
  1598. X            tce->sys,tce->pid);
  1599. X        tce = tce->next;
  1600. X    }
  1601. X
  1602. X    exit(0);
  1603. X}    /* end of main */
  1604. X
  1605. X/* vi: set tabstop=4 shiftwidth=4: */
  1606. X/* end of ecuxls.c */
  1607. SHAR_EOF
  1608. chmod 0644 excel/ecuxls.c ||
  1609. echo 'restore of excel/ecuxls.c failed'
  1610. Wc_c="`wc -c < 'excel/ecuxls.c'`"
  1611. test 37790 -eq "$Wc_c" ||
  1612.     echo 'excel/ecuxls.c: original size 37790, current size' "$Wc_c"
  1613. fi
  1614. # ============= excel/log ==============
  1615. if test -f 'excel/log' -a X"$1" != X"-c"; then
  1616.     echo 'x - skipping excel/log (File already exists)'
  1617. else
  1618. echo 'x - extracting excel/log (Text)'
  1619. sed 's/^X//' << 'SHAR_EOF' > 'excel/log' &&
  1620. X01-09-1555-12123-04460-CONNECT tridom (555-1212) 9600 baud
  1621. X01-09-1555-12126-04460-DISCONNECT tridom (555-1212) 7327 02:02:07
  1622. X01-09-1555-12125-05555-CONNECT n4vu (555-1212V) 9600 baud
  1623. X01-09-1555-12128-05555-DISCONNECT n4vu (555-1212V) 187 00:03:07
  1624. X01-09-1555-12121-05588-CONNECT n4vu (555-1212V) 9600 baud
  1625. X01-09-1555-12123-05588-DISCONNECT n4vu (555-1212V) 113 00:01:53
  1626. X01-09-1555-12121-05838-CONNECT p1so (555-1212PF) 9600 baud
  1627. X01-09-1555-12121-05838-DISCONNECT p1so (555-1212PF) 23 00:00:23
  1628. X01-09-1555-12122-05838-CONNECT kd4nc (555-1212C) 19200 baud
  1629. X01-09-1555-12126-05838-RECEIVE success: afterlint.c (4060 bytes)
  1630. X01-09-1555-12126-05838-RECEIVE success: ecu.c (9889 bytes)
  1631. X01-09-1555-12126-05838-RECEIVE success: ecu.h (4175 bytes)
  1632. X01-09-1555-12126-05838-RECEIVE success: ecuicmd.c (12787 bytes)
  1633. X01-09-1555-12127-05838-RECEIVE success: eculine.c (23999 bytes)
  1634. X01-09-1555-12128-05838-RECEIVE success: ecuphone.c (48334 bytes)
  1635. X01-09-1555-12128-05838-RECEIVE success: ecurcvr.c (31419 bytes)
  1636. X01-09-1555-12128-05838-RECEIVE success: ecushm.h (3040 bytes)
  1637. X01-09-1555-12129-05838-RECEIVE success: ecuvmin.h (585 bytes)
  1638. X01-09-1555-12129-05838-RECEIVE success: ecuxenix.c (14172 bytes)
  1639. X01-09-1555-12129-05838-RECEIVE success: gint.c (6599 bytes)
  1640. X01-09-1555-12120-05838-RECEIVE success: lint_args.h (27013 bytes)
  1641. X01-09-1555-12120-05838-RECEIVE success: pcmd.c (24245 bytes)
  1642. X01-09-1555-12120-05838-RECEIVE success: pprintf.c (3525 bytes)
  1643. X01-09-1555-12121-05838-RECEIVE success: stdio_lint.h (1286 bytes)
  1644. X01-09-1555-12122-05838-DISCONNECT kd4nc (555-1212C) 7238 02:00:38
  1645. SHAR_EOF
  1646. chmod 0644 excel/log ||
  1647. echo 'restore of excel/log failed'
  1648. Wc_c="`wc -c < 'excel/log'`"
  1649. test 1563 -eq "$Wc_c" ||
  1650.     echo 'excel/log: original size 1563, current size' "$Wc_c"
  1651. fi
  1652. exit 0
  1653.  
  1654. exit 0 # Just in case...
  1655. -- 
  1656. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1657. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1658. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1659. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1660.